<template>
  <div id="app">
    <img src="./assets/logo.png">
    <div v-if="isLogined">
      <HomePage/>
    </div>
    <div v-else>
      <LoginPage/>
    </div>
  </div>
</template>

<script>
import HomePage from './components/HomePage'
import LoginPage from './components/LoginPage'
import global from './global'

export default {
  name: 'App',
  components: {
    HomePage,
    LoginPage
  },
  data () {
    return {
      isLogined: global.isLoggedIn()
    }
  },
  created () {
    this.$axios.post('web_api/isLogined', {
      session_id: global.getSession_id(),
      session_vc: global.getSession_vc()
    }).then((res) => {
      this.isLogined = res.data.data
    }).catch((res) => {
      console.log(res)
      if (res.response.status === 412) {
        global.logout()
      }
    }).finally((res) => {
      console.log('finally:' + res)
    })
    global.onChange = loggedIn => {
      this.isLogined = loggedIn
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
